package net.jjjshop.common.service.lbt.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.jjjshop.common.entity.lbt.LbLineUp;
import net.jjjshop.common.entity.lbt.LbSysConfigEntity;
import net.jjjshop.common.mapper.lbt.LbLineUpMapper;
import net.jjjshop.common.service.lbt.LbLineUpService;
import net.jjjshop.common.service.lbt.LbSysConfigService;
import net.jjjshop.common.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * 用户公排 接口实现类
 */

@Service("LbLineUpService")
public class LbLineUpServiceImpl extends ServiceImpl<LbLineUpMapper, LbLineUp> implements LbLineUpService {

    @Autowired
    private LbLineUpMapper dao;
    @Autowired
    private UserService userService;
    @Autowired
    private LbSysConfigService sysConfigService;

    @Override
    public LbLineUp getStatus1(Integer pid) {
        QueryWrapper<LbLineUp> wrapper = new QueryWrapper<>();
        wrapper.eq("status", 1);
//        wrapper.eq("pid",pid);
        LbLineUp lineUps = dao.selectOne(wrapper);

        return lineUps;
    }

    @Override
    public LbLineUp setUpOrder(Integer pid) {
        Integer auto = null;
        LbSysConfigEntity lbSysConfigEntity = sysConfigService.selectSysConfig();
//        if (null != lbSysConfigEntity) {
//            auto = lbSysConfigEntity.getAutoQueue();
//        }
//        if (null != auto && auto.intValue() == 1) {
//            return dao.autoOrderUp();
//        }
        QueryWrapper<LbLineUp> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("id");
//        wrapper.eq("pid",pid);
        wrapper.eq("status", 0);
        List<LbLineUp> lineUps = dao.selectList(wrapper);
        if (null != lineUps && !lineUps.isEmpty()) {
            return lineUps.get(0);
        }
        return null;
    }

    @Override
    public LbLineUp getAutoUpOrder() {
        return null;
    }

    @Override
    public Integer pdNum(Date time,Integer pid) {
        return dao.gpNum(time,pid);
    }
    @Override
    public Integer getCount(LbLineUp lbLineUp) {
        return dao.getCount(lbLineUp);
    }

    @Override
    public Integer gpNum(Integer uid,Integer shopId) {
        return dao.gpNum2(uid,shopId);
    }

    @Override
    public Integer getLineNum(Integer pid) {
        return dao.getLineNum(pid);
    }


}
